package chuyentrung.racehorses;

import javax.microedition.khronos.opengles.GL10;

import chuyentrung.racehorses.framework.gl.Camera2D;
import chuyentrung.racehorses.framework.gl.SpriteBatcher;
import chuyentrung.racehorses.framework.impl.GLGraphics;

public class WorldRender {
	public static final float FRUSTUM_WIDTH = 10;
	public static final float FRUSTUM_HEIGHT = 15;
	
	private GLGraphics glGraphics;
	private World world;
	private Camera2D cam;
	private SpriteBatcher batcher;
	
	
	public WorldRender (GLGraphics glGraphics, SpriteBatcher batcher, World world) {
		this.glGraphics = glGraphics;
		this.world = world;
		this.cam = new Camera2D(glGraphics, FRUSTUM_WIDTH, FRUSTUM_HEIGHT);
		this.batcher = batcher;
	}
	
	
	public void render() {
		if (true){
			// set positon for cam
		}
		cam.setViewportAndMatrices();
		renderBackground();
		//renderObject();
	}
	
	
	public void renderBackground() {
		batcher.beginBatch(Assets.background);
		batcher.drawSprite(cam.position.x, cam.position.y, 
							FRUSTUM_WIDTH, 
							FRUSTUM_HEIGHT, 
							Assets.bgPlay);
		batcher.endBatch();
	}
	
	
	public void renderObject() {
		GL10 gl = glGraphics.getGL();
		gl.glEnable(GL10.GL_BLEND);
		gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
		
		batcher.beginBatch(Assets.items);
		
		// code render objects
		
		batcher.endBatch();
		gl.glDisable(GL10.GL_BLEND);
	}
}
